package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocLoadStatusDao;
import com.irdstudio.cdp.pboc.service.domain.PbocLoadStatus;
import com.irdstudio.cdp.pboc.service.facade.PbocLoadStatusService;
import com.irdstudio.cdp.pboc.service.vo.PbocLoadStatusVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 贷款状态信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocLoadStatusService")
public class PbocLoadStatusServiceImpl implements PbocLoadStatusService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocLoadStatusServiceImpl.class);

	@Autowired
	private PbocLoadStatusDao pbocLoadStatusDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocLoadStatus(PbocLoadStatusVO inPbocLoadStatusVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocLoadStatusVo.toString());
		int num = 0;
		try {
			PbocLoadStatus pbocLoadStatus = new PbocLoadStatus();
			beanCopy(inPbocLoadStatusVo, pbocLoadStatus);
			num = pbocLoadStatusDao.insertPbocLoadStatus(pbocLoadStatus);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocLoadStatusVO inPbocLoadStatusVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocLoadStatusVo);
		int num = 0;
		try {
			PbocLoadStatus pbocLoadStatus = new PbocLoadStatus();
			beanCopy(inPbocLoadStatusVo, pbocLoadStatus);
			num = pbocLoadStatusDao.deleteByPk(pbocLoadStatus);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocLoadStatusVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocLoadStatusVO inPbocLoadStatusVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocLoadStatusVo.toString());
		int num = 0;
		try {
			PbocLoadStatus pbocLoadStatus = new PbocLoadStatus();
			beanCopy(inPbocLoadStatusVo, pbocLoadStatus);
			num = pbocLoadStatusDao.updateByPk(pbocLoadStatus);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocLoadStatusVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocLoadStatusVO queryByPk(PbocLoadStatusVO inPbocLoadStatusVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocLoadStatusVo);
		try {
			PbocLoadStatus queryPbocLoadStatus = new PbocLoadStatus();
			beanCopy(inPbocLoadStatusVo, queryPbocLoadStatus);
			PbocLoadStatus queryRslPbocLoadStatus = pbocLoadStatusDao.queryByPk(queryPbocLoadStatus);
			if (Objects.nonNull(queryRslPbocLoadStatus)) {
				PbocLoadStatusVO outPbocLoadStatusVo = beanCopy(queryRslPbocLoadStatus, new PbocLoadStatusVO());
				logger.debug("当前查询结果为:"+ outPbocLoadStatusVo.toString());
				return outPbocLoadStatusVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}

	/**
	 * @description:根据贷款基本信息表的外键进行查询
	 * @param fids
	 * @return
	 * @date:2018年12月27日 下午8:06:07
	 * @author:hengyh
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<PbocLoadStatusVO> queryByFId(List<String> fids)  throws Exception {
		logger.debug("当前查询参数信息为:"+ fids);
		List<PbocLoadStatusVO> list = null;
		try {
			List<PbocLoadStatus> pbocLoadStatuss = pbocLoadStatusDao.queryByFID(fids);
			list = (List<PbocLoadStatusVO>) beansCopy(pbocLoadStatuss, PbocLoadStatusVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return list;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLoadStatusVO> queryAllOwner(PbocLoadStatusVO pbocLoadStatusVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocLoadStatusVO> list = null;
		try {
			List<PbocLoadStatus> pbocLoadStatuss = pbocLoadStatusDao.queryAllOwnerByPage(pbocLoadStatusVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocLoadStatuss.size());
			pageSet(pbocLoadStatuss, pbocLoadStatusVo);
			list = (List<PbocLoadStatusVO>) beansCopy(pbocLoadStatuss, PbocLoadStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLoadStatusVO> queryAllCurrOrg(PbocLoadStatusVO pbocLoadStatusVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocLoadStatus> pbocLoadStatuss = pbocLoadStatusDao.queryAllCurrOrgByPage(pbocLoadStatusVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocLoadStatuss.size());
		List<PbocLoadStatusVO> list = null;
		try {
			pageSet(pbocLoadStatuss, pbocLoadStatusVo);
			list = (List<PbocLoadStatusVO>) beansCopy(pbocLoadStatuss, PbocLoadStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLoadStatusVO> queryAllCurrDownOrg(PbocLoadStatusVO pbocLoadStatusVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocLoadStatus> pbocLoadStatuss = pbocLoadStatusDao.queryAllCurrDownOrgByPage(pbocLoadStatusVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocLoadStatuss.size());
		List<PbocLoadStatusVO> list = null;
		try {
			pageSet(pbocLoadStatuss, pbocLoadStatusVo);
			list = (List<PbocLoadStatusVO>) beansCopy(pbocLoadStatuss, PbocLoadStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

}
